<!-- ToolTip.vue -->
<template>
  <div v-show="isVisible" class="tooltip">
    <div class="tooltip-content">{{ content }}</div>
  </div>
</template>

<script>
export default {
  props: {
    content: String,
    isVisible: Boolean,
  },
  data() {
    return {
      left: 0,
      top: 0,
    };
  },
  methods: {
    updatePosition(event) {
      this.left = event.clientX + 10;
      this.top = event.clientY + 10;
    },
  },
  created() {
    this.$bus.$on("updateTooltipPosition", this.updatePosition);
  },
  beforeDestroy() {
    this.$bus.$off("updateTooltipPosition", this.updatePosition);
  },
};
</script>

<style scoped lang="scss">
.tooltip {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.tooltip-content {
  padding: 8px 12px;
  background-color: white;
  color: #6a6969;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 400;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border: 1px solid #cdcccc;
  /* 设置固定宽度 */
  width: 424px; /* 自定义宽度 */
  max-height: 120px; /* 可选：设置最大高度，超出会显示滚动条 */
  overflow-y: auto; /* 可选：启用垂直滚动 */

  /* 保留换行并允许自动换行 */
  white-space: pre-wrap;
  word-wrap: break-word;
}

.tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 15px; /* 调整箭头位置 */
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border: 1px solid #cdcccc;
  border-color: white transparent transparent transparent;
}
</style>
